<template>
  <div class="container">
    <div class="c-button">
      <el-button @click="handleExport" class="button">导出数据</el-button>
      <el-input
        :style="{width: '200px',marginLeft: '10px'}"
        placeholder="请输入内容"
        @keyup.enter.native="handleSearch"
        suffix-icon="el-icon-zoom-in"
        v-model="searchValue"
      ></el-input>
    </div>
    <div class="c-form">
      <el-table
        :data="listData"
        style="width: 100%"
        :header-cell-style="{color: 'white', backgroundColor: '#267fc2', textAlign: 'center'}"
        :cell-style="{textAlign: 'center'}"
      >
        <el-table-column type="index" width="150" label="序号"></el-table-column>
        <el-table-column prop="department" label="单位" width="220"></el-table-column>
        <el-table-column prop="phone_munber" label="当前值班人员电话" width="220"></el-table-column>
        <el-table-column prop="allcard" label="总打卡次数" width="220"></el-table-column>
        <el-table-column prop="offline" label="离岗次数" width="220"></el-table-column>
        <el-table-column prop="attendance" label="出勤率" width="220"></el-table-column>
      </el-table>
      <div class="c-page">
        <el-pagination
          @current-change="handleCurrentChange"
          background
          layout="prev, pager, next"
          :total="page.total"
        ></el-pagination>
      </div>
    </div>
    <div class="c-export" v-if="isExport">
      <div class="c-title">导出数据</div>
      <div class="body">
        <el-input class="row1" v-model="start" placeholder="请输入开始时间，如：2019-12-11"></el-input>
        <el-input v-model="end" placeholder="请输入结束时间，如：2019-12-11"></el-input>
      </div>
      <div class="c-operation">
        <el-button @click="handleSure" type="primary">确定</el-button>
        <el-button @click="handleReturn" type="primary">取消</el-button>
      </div>
    </div>
  </div>
</template>

<style lang="less" scope>
.container {
  position: relative;
}
.c-button {
  position: absolute;
  top: 50px;
  left: 150px;
}
.button {
  background-color: #267fc2;
  color: white;
}
.c-form {
  position: absolute;
  top: 120px;
  left: 150px;
}
.c-page {
  margin-top: 20px;
  display: flex;
  justify-content: center;
}
.c-export {
  width: 500px;
  height: 400px;
  background-color: white;
  box-shadow: 0px 11px 16px 4px rgba(0, 0, 0, 0.25);
  border-radius: 5px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  overflow: hidden;
  z-index: 50;
}
.c-title {
  text-align: center;
  color: white;
  padding: 20px 0;
  background-color: #267fc2;
}
.body {
  width: 300px;
  margin-top: 100px;
  margin-left: 100px;
}
.row1 {
  margin-bottom: 20px;
}
.c-operation {
  margin-top: 50px;
  display: flex;
  justify-content: center;
}
</style>

<script>
import RemoteData from "./mixins/RemoteData";
export default {
  mixins: [
    RemoteData({
      listData: "statistic/alldata"
    })
  ],
  data() {
    return {
      searchValue: "",
      isExport: false,
      start: "",
      end: "",
      token: sessionStorage.getItem("token").slice(7)
    };
  },
  methods: {
    handleExport() {
      this.isExport = !this.isExport;
    },
    handleSearch() {
      this.$http
        .get("statistic/search", {
          params: {
            department: this.searchValue
          }
        })
        .then(res => {
          console.log(res.data.data);
          let searchData = res.data.data;
          this.updateData(searchData);
        });
    },
    handleReturn() {
      this.isExport = !this.isExport;
    },
    handleSure() {
      window.open(
        "http://duty.myxy99.cn/api/statistic/export?startdate=" +
          this.start +
          "&enddate=" +
          this.end +
          "&token=" +
          this.token
      );
    },
    handleCurrentChange(val) {
      this.$http
        .get("http://duty.myxy99.cn/api/statistic/alldata?page=" + val)
        .then(res => {
          let pageData = res.data.data;
          this.updateData(pageData);
        });
    }
  }
};
</script>